package com.saasitems.admin.web.common;

import com.saasitems.admin.model.MediaRes;
import com.saasitems.common.utils.DateUtils;
import com.saasitems.common.utils.PropertiesUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.File;

/**
 * Created by Administrator on 2017/4/19.
 */
public class UtilFromDb {
    /**
     * 取得资源地址
     * @param ms
     * @return
     */
    public static String getPathFromMS(MediaRes ms) {

        String fileName = "";
        if (StringUtils.isNotBlank(ms.getFileExt())) {
            fileName = ms.getId() + "." + ms.getFileExt();
        } else {
            fileName = ms.getId();
        }
        String formatDate = DateUtils.formatDate(ms.getCreTime());

        String serverPath = PropertiesUtil.newInstance().getStringByKey("SERVER.URL");
        if (StringUtils.isBlank(serverPath)) {
            serverPath = "";
        }
        return serverPath + "/" + formatDate.substring(0, 6) + "/" + fileName;
    }
}
